home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / djgpp / contrib / pdcurs22 / src / private / pdcwin.c < prev   
Encoding:
C/C++ Source or Header  |  1995-01-26  |  6.6 KB  |  267 lines

  1. /*
  2. ***************************************************************************
  3. * This file comprises part of PDCurses. PDCurses is Public Domain software.
  4. * You may use this code for whatever purposes you desire. This software
  5. * is provided AS IS with NO WARRANTY whatsoever.
  6. * Should this software be used in another application, an acknowledgement
  7. * that PDCurses code is used would be appreciated, but is not mandatory.
  8. *
  9. * Any changes which you make to this software which may improve or enhance
  10. * it, should be forwarded to the current maintainer for the benefit of 
  11. * other users.
  12. *
  13. * The only restriction placed on this code is that no distribution of
  14. * modified PDCurses code be made under the PDCurses name, by anyone
  15. * other than the current maintainer.
  16. * See the file maintain.er for details of the current maintainer.
  17. ***************************************************************************
  18. */
  19. #define    CURSES_LIBRARY    1
  20. #include <curses.h>
  21.  
  22. #ifndef NO_MEMORY_H
  23. #include <memory.h>
  24. #endif
  25.  
  26. #ifdef PDCDEBUG
  27. char *rcsid_PDCwin  = "$Id$";
  28. #endif
  29.  
  30. /*man-start*********************************************************************
  31.  
  32.   PDC_copy_win()    - Common routine for copywin(), overlay() and overwrite()
  33.      functions.
  34.  
  35.   PDCurses Description:
  36.      This function copies the region of the source window specified
  37.      over the specified region of the destination window. All validation
  38.      of limits are done by the calling function.
  39.  
  40.      Thanks to Andreas Otte (venn@uni-paderborn.de) for the code changes.
  41.  
  42.   PDCurses Errors:
  43.      ERR is returned if either src or dst windows are NULL;
  44.  
  45.   Portability:
  46.      PDCurses    int    PDC_copy_win( WINDOW* src_w, WINDOW* dst_w
  47.              int src_tr,int src_tc,int src_br,int src_bc,
  48.              int dst_tr,int dst_tc,int dst_br,int dst_bc,bool overlay);
  49.  
  50. **man-end**********************************************************************/
  51.  
  52. int    PDC_copy_win(WINDOW *src_w, WINDOW *dst_w,
  53.              int src_tr,int src_tc,int src_br,int src_bc,
  54.              int dst_tr,int dst_tc,int dst_br,int dst_bc,bool overlay)
  55. {
  56.     int*    minchng=0;
  57.     int*    maxchng=0;
  58.     chtype*    w1ptr=NULL;
  59.     chtype*    w2ptr=NULL;
  60.     int    col=0;
  61.     int    line=0;
  62.     int    xdiff = src_bc - src_tc;
  63.     int    ydiff = src_br - src_tr;
  64.     int    y1=0;
  65.  
  66. #ifdef PDCDEBUG
  67.     if (trace_on) PDC_debug("PDC_copy_win() - called\n");
  68. #endif
  69.  
  70.     if (src_w == (WINDOW *)NULL)    return( ERR );
  71.     if (dst_w == (WINDOW *)NULL)    return( ERR );
  72.  
  73.     minchng    = dst_w->_firstch;
  74.     maxchng    = dst_w->_lastch;
  75.  
  76.  
  77.     for (y1 = 0; y1 < dst_tr; y1++)
  78.         {
  79.         minchng++;
  80.         maxchng++;
  81.         }
  82.  
  83.     for (line = 0; line < ydiff; line++)
  84.     {
  85.         register int fc;
  86.         register int lc;
  87.  
  88.         w1ptr = src_w->_y[line+src_tr]+src_tc;
  89.         w2ptr = dst_w->_y[line+dst_tr]+dst_tc;
  90.         fc    = _NO_CHANGE;
  91.  
  92.         for (col = 0; col < xdiff; col++)
  93.         {
  94.             if ((*w1ptr) != (*w2ptr)
  95.             &&  !((*w1ptr & A_CHARTEXT) == src_w->_blank && overlay))
  96.             {
  97.                 *w2ptr = *w1ptr;
  98.                 if (fc == _NO_CHANGE)
  99.                 {
  100.                     fc = col+dst_tc;
  101.                 }
  102.                 lc = col+dst_tc;
  103.             }
  104.             w1ptr++;
  105.             w2ptr++;
  106.         }
  107.  
  108.         if (*minchng == _NO_CHANGE)
  109.         {
  110.             *minchng = fc;
  111.             *maxchng = lc;
  112.         }
  113.         else    if (fc != _NO_CHANGE)
  114.         {
  115.             if (fc < *minchng)    *minchng = fc;
  116.             if (lc > *maxchng)    *maxchng = lc;
  117.         }
  118.         minchng++;
  119.         maxchng++;
  120.     }
  121.     return( OK );
  122. }
  123.  
  124. /*man-start*********************************************************************
  125.  
  126.   PDC_makenew()    - Create a WINDOW* (sans line allocation)
  127.  
  128.   PDCurses Description:
  129.      This is a private PDCurses routine.
  130.  
  131.      Allocates all data for a new WINDOW* except the actual lines
  132.      themselves.
  133.  
  134.   PDCurses Return Value:
  135.      This function returns a valid WINDOW* on success and NULL on error.
  136.  
  137.   PDCurses Errors:
  138.      If PDC_makenew() is unable to allocate memory for the window
  139.      structure, it will free all allocated memory and return
  140.      a NULL pointer.
  141.  
  142.   Portability:
  143.      PDCurses    WINDOW* PDC_makenew( int num_lines, int num_columns,
  144.                       int begy, int begx );
  145.  
  146. **man-end**********************************************************************/
  147.  
  148. WINDOW*    PDC_makenew(int num_lines, int num_columns, int begy, int begx)
  149. {
  150. extern    void*    (*mallc)( size_t );
  151. extern    void*    (*callc)( size_t, size_t );
  152. extern    void    (*fre)( void* );
  153.  
  154.     short    i=0;
  155.     WINDOW *win=NULL;
  156.  
  157. #ifdef PDCDEBUG
  158.     if (trace_on) PDC_debug("PDC_makenew() - called: lines %d cols %d begy %d begx %d\n",num_lines,num_columns,begy,begx);
  159. #endif
  160.  
  161.     /*
  162.     *    Use the standard runtime malloc/calloc package or use
  163.     *    the user's emalloc/ecalloc package.
  164.     *
  165.     *    Allocate the window structure itself
  166.     */
  167.     if ((win = (*mallc)(sizeof(WINDOW))) == (WINDOW *)NULL)
  168.     {
  169.         return( win );
  170.     }
  171.  
  172.     /*
  173.     * allocate the line pointer array
  174.     */
  175.     if ((win->_y = (*callc)(num_lines, sizeof(chtype *))) == NULL)
  176.     {
  177.         (*fre)(win);
  178.         return( (WINDOW *)NULL );
  179.     }
  180.  
  181.     /*
  182.     * allocate the minchng and maxchng arrays
  183.     */
  184.     if ((win->_firstch = (*callc)(num_lines, sizeof(int))) == NULL)
  185.     {
  186.         (*fre)(win->_y);
  187.         (*fre)(win);
  188.         return( (WINDOW *)NULL );
  189.     }
  190.     if ((win->_lastch = (*callc)(num_lines, sizeof(int))) == NULL)
  191.     {
  192.         (*fre)(win->_firstch);
  193.         (*fre)(win->_y);
  194.         (*fre)(win);
  195.         return( (WINDOW *)NULL );
  196.     }
  197.  
  198.     /*
  199.     * initialize window variables
  200.     */
  201.     win->_curx = 0;
  202.     win->_cury = 0;
  203.     win->_maxy = num_lines;        /* real max screen size */
  204.     win->_maxx = num_columns;    /* real max screen size */
  205.     win->_pmaxy = num_lines;    /* real max window size */
  206.     win->_pmaxx = num_columns;    /* real max window size */
  207.     win->_begy = begy;
  208.     win->_begx = begx;
  209.     win->_lastpy = 0;
  210.     win->_lastpx = 0;
  211.     win->_lastsy1 = 0;
  212.     win->_lastsx1 = 0;
  213.     win->_lastsy2 = LINES-1;
  214.     win->_lastsx2 = COLS-1;
  215.     win->_flags = 0;
  216.     win->_attrs = 0;        /* No attributes */
  217.     win->_tabsize = 8;
  218.     win->_clear = (bool) ((num_lines == LINES) && (num_columns == COLS));
  219.     win->_leave = FALSE;
  220.     win->_scroll = FALSE;
  221.     win->_nodelay = FALSE;
  222.     win->_use_keypad = FALSE;
  223.     win->_immed = FALSE;
  224.     win->_use_idl = FALSE;
  225.     win->_use_idc = TRUE;
  226.     win->_tmarg = 0;
  227.     win->_bmarg = num_lines - 1;
  228.     win->_title = NULL;
  229.     win->_title_ofs = 1;
  230.     win->_title_attr = win->_attrs;
  231.     win->_blank = ' ';
  232.     win->_parx = win->_pary = -1;
  233.     win->_parent = NULL;
  234. /* wrs 4/10/93 -- initialize background to blank */
  235.     win->_bkgd = ' ';
  236.     /*
  237.     * init to say window unchanged
  238.     */
  239.     for (i = 0; i < num_lines; i++)
  240.     {
  241.         win->_firstch[i] = 0;
  242.         win->_lastch[i] = num_columns - 1;
  243.     }
  244.  
  245.     /*
  246.     * set flags for window properties
  247.     */
  248.     if ((begy + num_lines) == LINES)
  249.     {
  250.         win->_flags |= _ENDLINE;
  251.         if ((begx == 0) &&
  252.             (num_columns == COLS) &&
  253.             (begy == 0))
  254.         {
  255.             win->_flags |= _FULLWIN;
  256.         }
  257.     }
  258.  
  259.     if (((begy + num_lines) == LINES) &&
  260.         ((begx + num_columns) == COLS))
  261.     {
  262.         win->_flags |= _SCROLLWIN;
  263.     }
  264.     return( win );
  265. }
  266.